package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.shopping.dal.entitys.Panel;
import com.cskaoyan.shopping.dal.entitys.PanelContent;
import com.cskaoyan.shopping.dto.AllProductResponse;
import com.cskaoyan.shopping.dto.ItemCatDto;
import com.cskaoyan.shopping.dto.PanelDto;
import com.cskaoyan.shopping.dto.ShowHomePageDto;
import com.cskaoyan.shopping.form.PageRequest;
import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * @ClassName:ProductController
 * @Auther: HeXianZu
 * @Description:
 * @Date: 2022/10/25 17:06
 */
@RestController
public class ProductController {

    @Autowired
    IProductService productService;

    /**
     * 主页显示
     * @return
     */
    @GetMapping("/shopping/homepage")
    public ResponseData shoppingHomepage() {
        // 调用service层查询主页显示的数据
        List<Panel> panels = productService.shoppingHomepage();
        return new ResponseUtil().setData(panels);
    }

    /**
     * 导航栏显示
     * @return
     */
    @GetMapping("/shopping/navigation")
    public ResponseData shoppingNavigation() {

        List<PanelContent> panelContents = productService.shoppingNavigation();
        return new ResponseUtil().setData(panelContents);
    }

    /**
     * 例举所有商品种类
     * @return
     */
    @GetMapping("/shopping/categories")
    public ResponseData shoppingCategories() {

        List<ItemCatDto> itemCatDto = productService.shoppingCategories();
        return new ResponseUtil().setData(itemCatDto);
    }

    /**
     * 获取商品详情
     * @param id:商品id
     * @return
     */
    @GetMapping("/shopping/product/{id}")
    public ResponseData shoppingProduct(@PathVariable("id") Long id){

        ProductDetailDto productDetailDto = productService.getProductDetail(id);
        return new ResponseUtil().setData(productDetailDto);
    }


    /**
     * 请求网址： http://124.221.21.69:8080/shopping/goods?page=1&size=20&sort=&priceGt=&priceLte=&cid=231
     * 分页查询商品列表
     *@auther: yy
     * @return
     */
    @GetMapping("/shopping/goods")
    public ResponseData goods(PageRequest pageRequest) {

        //1.通过请求参数查询所有商品（分页）
        AllProductResponse allProduct = productService.getAllProduct(pageRequest);
        return new ResponseUtil().setData(allProduct);
    }


    /**
     * 查询推介商品
     * 请求网址：http://124.221.21.69:8080/shopping/recommend
     *@auther: yy
     * @return
     */
    @GetMapping("/shopping/recommend")
    public ResponseData queryRecommendProduct() {

        Set<PanelDto> recommendGoods = productService.getRecommendGoods();

        return new ResponseUtil().setData(recommendGoods);
    }

}
